package com.lagou.service.impl;

import com.lagou.base.StatusCode;
import com.lagou.dao.CourseContentDao;
import com.lagou.dao.impl.CourseContentDaoImpl;
import com.lagou.pojo.Course;
import com.lagou.pojo.Course_Lesson;
import com.lagou.pojo.Course_Section;
import com.lagou.service.CourseContentService;
import com.lagou.utils.DateUtils;

import java.util.List;

public class CourseContentServiceImpl implements CourseContentService {

    CourseContentDao dao = new CourseContentDaoImpl();
    @Override
    public List<Course_Section> findSectionAndLessonByCourseId(Integer courseId) {

        List<Course_Section> course_sections = dao.findSectionAndLessonByCourseId(courseId);
        return course_sections;
    }

    @Override
    public String saveSection(Course_Section courseSection) {
        // 1.补全章节信息
        courseSection.setStatus(2); // 0隐藏 1待更新 2已发布
        String date = DateUtils.getDateFormart();
        courseSection.setCreate_time(date);
        courseSection.setUpdate_time(date);
        int i = dao.saveSection(courseSection);
        String str;
        if(i>0){
            str = StatusCode.SUCCESS.toString();
            return str;
        }
        str = StatusCode.FAIL.toString();
        return str;
    }

    @Override
    public Course findCourseByCourseId(Integer id) {
        Course course = dao.findCourseByCourseId(id);

        return course;
    }

    @Override
    public String updateSection(Course_Section courseSection) {
        // 补全信息
        String dateFormart = DateUtils.getDateFormart();
        courseSection.setUpdate_time(dateFormart);
        int result = dao.updateSection(courseSection);
        String str;
        if(result>0){
            str = StatusCode.SUCCESS.toString();
            return str;
        }else{
            str = StatusCode.FAIL.toString();
            return str;
        }
    }

    @Override
    public String insertLesson(Course_Lesson courseLesson) {
        String date = DateUtils.getDateFormart();
        courseLesson.setCreate_time(date);
        courseLesson.setUpdate_time(date);
        int i = dao.insertLesson(courseLesson);
        String str;
        if(i>0){
            str = StatusCode.SUCCESS.toString();
            return str;
        }else{
            str = StatusCode.FAIL.toString();
            return str;
        }

    }

    @Override
    public String updateLesson(Course_Lesson courseLesson) {
        // 补全信息
        String dateFormart = DateUtils.getDateFormart();
        courseLesson.setUpdate_time(dateFormart);
        int i = dao.updateLesson(courseLesson);
        String str;
        if(i>0){
            str = StatusCode.SUCCESS.toString();
            return str;
        }else{
            str = StatusCode.FAIL.toString();
            return str;
        }

    }
}
